package main

import _ "github.com/go-sql-driver/mysql"
import (
	_ "database/sql"
	"database/sql"
	"fmt"
)

func main(){

	//连接数据库
	db, err :=sql.Open("mysql","root:root@tcp(localhost:3306)/test?charset=utf8")

	if err != nil{
		panic(err)
	}

	//插入记录
/*	stmt, err :=db.Prepare("INSERT user_info SET username=?, departname=?,create_time=?")

	res, err := stmt.Exec("zhangsan", "技术部", "2018-1-1")
	id, err :=res.LastInsertId()
	if err != nil {
		panic(err)
	}

	fmt.Println(id)
*/


	//修改记录
/*	stmt, err :=db.Prepare("update user_info set username=? where id=?")

	res, err :=stmt.Exec("lisi","1")
	id, err :=res.RowsAffected()
	if err != nil {
		panic(err)
	}

	fmt.Println(id)
*/
	//查询记录
/*	rows, err := db.Query("SELECT * FROM user_info")
	if err!=nil{
		panic(err)
	}

	for rows.Next() {
		var id int
		var username string
		var department string
		var create_time string
		err = rows.Scan(&id, &username, &department, &create_time)
		fmt.Println(id, username, department, create_time)
	}*/

	//删除记录
	stmt, err := db.Prepare("delete from user_info where id=?")
	res, err := stmt.Exec(1)

	fmt.Println(res)


}
